<?php
namespace App\Http\Query;

use Illuminate\Support\Facades\DB;

/*
 * 新商品情報
 *
 */
class NewsQuery
{

    // とりnew_flg=1
    public function getNews()
    {
        $sql = 'select * from news where  delete_flg = 0 order by sort_num desc';
        $news = DB::select($sql);
        return $news;
    }

    // ニュース 情報を保存
    public function saveNewsInfomation($param)
    {
        $sql = 'INSERT INTO  news (title, detail, sort_num, delete_flg, created_at, updated_at) VALUES (?,?,?,0,now(),now())';
        return DB::insert($sql, $param);
    }

    // ニュース 情報を削除
    public function deleteNewsInfomation($newsId)
    {
        $sql = 'UPDATE news  SET delete_flg = 1 WHERE  news_id = ?';
        $param = [$newsId];
        return DB::update($sql, $param);
    }

    // ニュース 情報を修正
    public function updateNewsInfomation($param)
    {
        $sql = 'UPDATE news  SET title = ?, detail = ?, sort_num = ?, created_at=now(), updated_at=now() WHERE  news_id = ?';
        return DB::update($sql, $param);
    }
}
